package tech.aistar.day03;

import java.util.Date;

/**
 * 本类用来演示: 日期
 *
 * @author: success
 * @date: 2022/7/20 9:06 上午
 */
public class DateDemo {
    public static void main(String[] args) {
        //1. 通过new关键字来构建一个日期对象
        Date now = new Date();
        System.out.println(now);//Wed Jul 20 09:07:15 CST 2022

        //2. 通过指定的年月日构建
        Date d = new Date(2022-1900,6,24);
        System.out.println(d);
        System.out.println(d.getYear()+1900);
        System.out.println(d.getMonth()+1);
        System.out.println(d.getDate());
        System.out.println(d.getDay());

        //应用 - 唯一性 - 订单号 - 基于它

        //3. Date类型转换成毫秒数
        long time = now.getTime();
        System.out.println(time);

        //4. 毫秒数=> 构建出新的Date
        //1. 通过构造Date(long time)
        //2. 通过void setTime(long time);

        now.setTime(1653278635662L);
        System.out.println(now);

        //可以针对year,month,date,hours,minutes,seconds 一一赋值
        Date dt = new Date();
        dt.setYear(2023-1900);
        dt.setMonth(4);

        System.out.println(dt);

        System.out.println(System.currentTimeMillis());
    }
}
